
{extend name=".././view/list.html" /}
{block name="jsset"}
{load href="__STATIC__/echarts/echarts.js" /}
{/block}
{block name="nav"}
<span class="layui-breadcrumb">
  <a href="">考试管理</a>
  <a href="">更多操作</a>
  <a href="">成绩查看</a>
  <a href="">各班级成绩统计表</a>
  <a><cite>{$list['webtitle']}</cite></a>
</span>
{/block}
{block name="search"}
<div class="layui-form-item">
  <label for="searchval" class="layui-form-label">
    关键字
  </label>
  <div class="layui-input-block">
    <input type="text" id="searchval" name="searchval" autocomplete="off" class="layui-input">
  </div>
</div>
<div class="layui-form-item">
  <label for="xueqi_id" class="layui-form-label" style="height: 100%">学期</label>
  <div class="layui-input-block">
    <input type="radio" name="xueqi_id" title="无" value="" lay-skin="primary" checked="true">
    {php} $category = categoryChildren(108);{/php}
    {volist name="category" id="vo"}
    <input type="radio" name="xueqi_id" title="{$vo.title}" value="{$vo.id}" lay-skin="primary">
    {/volist}
  </div>
</div>
<div class="layui-form-item">
  <label for="category_id" class="layui-form-label" style="height: 100%">考试类型</label>
  <div class="layui-input-block">
    {php} $category = categoryChildren(109);{/php}
    {volist name="category" id="vo"}
      <input type="checkbox" name="category_id[]" title="{$vo.title}" value="{$vo.id}" lay-skin="primary">
    {/volist}
  </div>
</div>
<div class="layui-form-item">
  <div class="layui-inline">
    <label for="title" class="layui-form-label">
      <span class="x-red">*</span>考试时间
    </label>
    <div class="layui-input-inline">
      <input type="text" class="layui-input" id="bfdate" name="bfdate" placeholder="起始：默认一年前的今天" value="{$list.data.bfdate|default=''}" autocomplete="off" lay-filter="riqi">
    </div>
    <div class="layui-input-inline">
      <input type="text" class="layui-input" id="enddate" name="enddate" placeholder="结束：默认明天" value="{$list.data.enddate|default=''}" autocomplete="off" lay-filter="riqi">
    </div>
  </div>
</div>


<input type="hidden" name="student_id" value="{$list.student_id}">
{/block}
{block name="table"}
  <table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="echart"}
  {volist name="$list.sbj" id="vo"}
    <div class="layui-col-xs6" style="width:100%; height:400px; margin-top: 45px; margin-bottom: 45px;" id="{$vo.lieming}"></div>
  {/volist}
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
<!--   <div class="layui-btn-container">
    <button class="layui-btn" lay-event="download">
      <i class="layui-icon layui-icon-download-circle"></i> 下载报告
    </button>
  </div> -->
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
  <a class="layui-btn-xs" lay-event="detail" title="查看"><i class="layui-icon layui-icon-search"></i></a>
</script>
<!-- 表格操作 -->
<script>
 // 设置列
  options.cols=[[ //表头
  {field:'id',type:'numbers',sort:true,width:50,title:'序号'}
  ,{field: 'id', title: '操作',toolbar: '#barDemo',minWidth:10}
  ,{field: 'kaoshiTitle',sort:true, title: '考试类型', minWidth:100}
  ,{field:'bfdate',title: '考试时间',sort:true, minWidth:150,templet:function(d){
    var date;
    date = d.enddate.split('-');
    endate = date[1] + '-' + date[2];
    endate = d.bfdate + '～' + endate;
    return endate;
  }}
  ,{field:'zuzhi_id',title: '组织单位',sort:true, minWidth:100}
  ]];

  var xk = '<?php echo json_encode($list["sbj"]);?>';
  xk = eval(decodeURIComponent(xk));
  for(x in xk)
  {
    options.cols[0].push({field:xk[x].lieming, title: xk[x].title , minWidth:100,sort: true});
  }
  options.cols[0].push({field: 'avg', title: '平均分', minWidth:100,sort: true});
  options.cols[0].push({field: 'sum', title: '总分', minWidth:100,sort: true});

  // 提交搜索条件后重载表格
  layui.use(['table','cjgl','laydate','element'],function(){
    var table = layui.table
    cjgl = layui.cjgl
    laydate = layui.laydate
    form = layui.form
    element = layui.element;

    //开始时间
    laydate.render({
      elem: '#bfdate'
      ,type: 'datetime'
      ,trigger: 'click' //采用click弹出
      ,format: 'yyyy-M-d' //可任意组合
      ,done: function(value, date, endDate){
        form.val("search",{
          "bfdate" : value,
        });
        $("#srcsubmit").click();
        // 添加图表中内容
        for(x in xk)
        {
          getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
        }
      }
    });
    //结束时间
    laydate.render({
      elem: '#enddate'
      ,type: 'datetime'
      ,trigger: 'click' //采用click弹出
      ,format: 'yyyy-M-d' //可任意组合
      ,done: function(value, date, endDate){
        form.val("search",{
          "enddate" : value,
        });
        $("#srcsubmit").click();
        // 添加图表中内容
        for(x in xk)
        {
          getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
        }
      }
    });

    // 监听表单提交
    form.on('submit(srcsubmit)', function(data){
      options.where = lForm.val("search");
      table.render(options);  //获取数据并渲染
      for(x in xk)
      {
        getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
      }
      return false;
    });


    // 添加图表中内容
    for(x in xk)
    {
      getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
    }

    //表头工具栏事件
    table.on('toolbar(mytable)', function(obj){
      switch(obj.event){
        case 'dels':
          var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
          cjgl.delAll(checkStatus,'/school','mytable');
          break;
        case 'add':
          cjgl.add('添加单位','/school/create','650','500');
          break;
        case 'download':
          cjgl.add('下载成绩','/chengji/bjtj/dwbiaoge/{$list.kaoshi_id}','650','300');
          break;
        };
      });


    //监听行工具条
    table.on('tool(mytable)', function(obj){
      var data = obj.data; //获得当前行数据
      var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
      var tr = obj.tr; //获得当前行 tr 的DOM对象
      switch(layEvent){
        case 'detail':// 查看
          cjgl.add(obj.data.kaoshiTitle + '考试成绩','/kaohao/index/read/' + obj.data.kaohao_id,'','',true);
          break;
      };
    });


    // 监听表单提交
    form.on('radio', function(data){
      for(x in xk)
      {
        getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
      }

      $("#srcsubmit").click();
    });


  // 监听表单提交
  form.on('checkbox', function(data){
    for(x in xk)
    {
      getDefenlv(xk[x].id,xk[x].lieming,xk[x].title);
    }

    $("#srcsubmit").click();
  });


   // 条形统计图--平均分
   function getDefenlv(sbjid, sbjlieming, sbjtitle){
    var id = sbjlieming;
    var url = '/tools/onestudentchengji/xkold';
    var val = form.val('search');
    val.subject_id = sbjid;
    var title = sbjtitle;
    createZhexian(id, url, val, title);
  }

});

  /**
  * 异步获取图表中的数据
  *
  * @access public
  * @param id 要添加数据的div
  * @param url 异步地址
  * @param val 异步时携带的参数
  * @param val 图表标题
  * @return array 返回类型
  */
  function createZhexian(id, url, val, title)
  {
    var myZhexian = echarts.init(document.getElementById(id));
    $.post(url,val).done(function (data) {
      myZhexian.setOption({
        title: {
          text: title
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: data.legend
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: data.xAxis,
        },
        yAxis: {
          type: 'value'
        },
        series: data.series,
      });
    });
  }
</script>
{/block}
